<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    提高生产效率！3个常用的开源工具库分享.md |  
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-develop/提高生产效率！3个常用的开源工具库分享"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  提高生产效率！3个常用的开源工具库分享.md
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/11/11/develop/%E6%8F%90%E9%AB%98%E7%94%9F%E4%BA%A7%E6%95%88%E7%8E%87%EF%BC%813%E4%B8%AA%E5%B8%B8%E7%94%A8%E7%9A%84%E5%BC%80%E6%BA%90%E5%B7%A5%E5%85%B7%E5%BA%93%E5%88%86%E4%BA%AB/" class="article-date">
  <time datetime="2020-11-10T16:00:00.000Z" itemprop="datePublished">2020-11-11</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/develop/">develop</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">4k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">18 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="提高生产效率！3个常用的开源工具库分享"><a href="#提高生产效率！3个常用的开源工具库分享" class="headerlink" title="提高生产效率！3个常用的开源工具库分享"></a>提高生产效率！3个常用的开源工具库分享</h1><p><strong>我们实际项目开发中是比较忌讳造轮子的，但是，自己在学习过程中造轮子绝对是对自己百利而无一害的！\</strong>造轮子是一种特别能够提高自己系统编程能力的手段。****</p>
<p>今天就分享几个我常用的开源工具库，希望对小伙伴们有帮助！</p>
<ol>
<li><strong>OSHI[1]</strong> ：一款为 Java 语言提供的基于 JNA 的（本机）操作系统和硬件信息库。</li>
<li><strong>EasyExcel[2]</strong> ：一款快速、简单避免 OOM 的 java 处理 Excel 工具。</li>
<li><strong>Hutool[3]</strong> : 一个非常实用的 Java 工具类库，对文件、流、加密解密、转码、正则、线程、XML 等 JDK 方法进行了封装。</li>
</ol>
<p>以下是较为详细一点的介绍，建议小伙伴们看完，方便自己快速上手，用在自己的项目中来提高生产效率。</p>
<h2 id="oshi"><a href="#oshi" class="headerlink" title="oshi"></a>oshi</h2><p><img src="http://iubest.gitee.io/pic/640-1601003797047.png" alt="img"></p>
<h3 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h3><p>OSHI 是一款为 Java 语言提供的基于 <strong>JNA</strong> 的（本机）操作系统和硬件信息库。</p>
<blockquote>
<p><strong>JNA(Java Native Access)</strong>[4]是一个开源的 Java 框架，是 Sun 公司推出的一种调用本地方法的技术，是建立在经典的 JNI 基础之上的一个框架。之所以说它是 JNI 的替代者，是因为 JNA 大大简化了调用本地方法的过程，使用很方便，基本上不需要脱离 Java 环境就可以完成。</p>
<p>JNI（Java Native Interface） 是 JDK 提供的一个编程接口，它允许 Java 程序调用其他语言编写的程序或者代码库，其实 JDK 本身的实现也大量用到 JNI 技术来调用本地 C 程序库。</p>
</blockquote>
<p><strong>通过 OSHI ，我们不需要安装任何其他本机库，就能查看内存和 CPU 使用率、磁盘和分区使用情况、设备、传感器等信息。</strong></p>
<p>OSHI 旨在提供一种跨平台的实现来检索系统信息，支持 Windows、Linux、MacOS、Unix 等主流操作系统。</p>
<p>官方是这样介绍 oshi 的：（翻译 Chrome 插件：<strong>Mate Translate</strong>）：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003797254.png" alt="img"></p>
<p>使用 oshi 你可以轻松制作出项目常用的系统监控功能，如下图所示：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003797252.png" alt="img"></p>
<h3 id="引入依赖"><a href="#引入依赖" class="headerlink" title="引入依赖"></a>引入依赖</h3><p>Maven</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- https:&#x2F;&#x2F;mvnrepository.com&#x2F;artifact&#x2F;com.github.oshi&#x2F;oshi-core --&gt;</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;com.github.oshi&lt;&#x2F;groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;oshi-core&lt;&#x2F;artifactId&gt;</span><br><span class="line">    &lt;version&gt;5.2.5&lt;&#x2F;version&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br></pre></td></tr></table></figure>

<p>Gradle</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; https:&#x2F;&#x2F;mvnrepository.com&#x2F;artifact&#x2F;com.github.oshi&#x2F;oshi-core</span><br><span class="line">compile group: &#39;com.github.oshi&#39;, name: &#39;oshi-core&#39;, version: &#39;5.2.5&#39;</span><br></pre></td></tr></table></figure>

<h3 id="功能演示"><a href="#功能演示" class="headerlink" title="功能演示"></a>功能演示</h3><p>获取硬件信息对象<code>HardwareAbstractionLayer</code> ：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;系统信息</span><br><span class="line">SystemInfo si &#x3D; new SystemInfo();</span><br><span class="line">&#x2F;&#x2F;操作系统信息</span><br><span class="line">OperatingSystem os &#x3D; si.getOperatingSystem();</span><br><span class="line">&#x2F;&#x2F;硬件信息</span><br><span class="line">HardwareAbstractionLayer hal &#x3D; si.getHardware();</span><br></pre></td></tr></table></figure>

<p>有了代表硬件信息的对象<code>HardwareAbstractionLayer</code> 之后，我们就可以获取硬件相关的信息了！</p>
<p>下面简单演示一下获取内存和 CPU 相关信息。</p>
<p><strong>1.获取内存相关信息</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;内存相关信息</span><br><span class="line">GlobalMemory memory &#x3D; hal.getMemory();</span><br><span class="line">&#x2F;&#x2F;获取内存总容量</span><br><span class="line">String totalMemory &#x3D; FormatUtil.formatBytes(memory.getTotal());</span><br><span class="line">&#x2F;&#x2F;获取可用内存的容量</span><br><span class="line">String availableMemory &#x3D; FormatUtil.formatBytes(memory.getAvailable());</span><br></pre></td></tr></table></figure>

<p>有了内存总容量和内存可用容量，你就可以计算出当前内存的利用率了。</p>
<p><strong>2.获取 CPU 相关信息</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;CPU相关信息</span><br><span class="line">CentralProcessor processor &#x3D; hal.getProcessor();</span><br><span class="line">&#x2F;&#x2F;获取CPU名字</span><br><span class="line">String processorName &#x3D; processor.getProcessorIdentifier().getName();</span><br><span class="line">&#x2F;&#x2F;获取物理CPU数</span><br><span class="line">int physicalPackageCount &#x3D; processor.getPhysicalPackageCount();</span><br><span class="line">&#x2F;&#x2F;获取物理核心数</span><br><span class="line">int physicalProcessorCount &#x3D; processor.getPhysicalProcessorCount();</span><br></pre></td></tr></table></figure>

<h2 id="EasyExcel"><a href="#EasyExcel" class="headerlink" title="EasyExcel"></a>EasyExcel</h2><h3 id="介绍-1"><a href="#介绍-1" class="headerlink" title="介绍"></a>介绍</h3><p>Java 解析、生成 Excel 常用的框架有 Apache poi、jxl ，但是这两个框架使用起来都不够优雅，并且<strong>非常耗内存</strong>，<strong>严重时会导致内存溢出</strong>。</p>
<p><strong>怎么解决这个问题呢？</strong></p>
<p>推荐你使用阿里开源的 EasyExcel。正如这个项目官网介绍的那样，<strong>这是一款快速、简单避免 OOM 的 java 处理 Excel 工具。</strong></p>
<p>官方是这样介绍 EasyExcel 的：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003797351.png" alt="img"></p>
<h3 id="引入依赖-1"><a href="#引入依赖-1" class="headerlink" title="引入依赖"></a>引入依赖</h3><p>Maven</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- https:&#x2F;&#x2F;mvnrepository.com&#x2F;artifact&#x2F;com.alibaba&#x2F;easyexcel --&gt;</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;com.alibaba&lt;&#x2F;groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;easyexcel&lt;&#x2F;artifactId&gt;</span><br><span class="line">    &lt;version&gt;2.2.6&lt;&#x2F;version&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br></pre></td></tr></table></figure>

<p>Gradle</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; https:&#x2F;&#x2F;mvnrepository.com&#x2F;artifact&#x2F;com.alibaba&#x2F;easyexcel</span><br><span class="line">compile group: &#39;com.alibaba&#39;, name: &#39;easyexcel&#39;, version: &#39;2.2.6&#39;</span><br></pre></td></tr></table></figure>

<h3 id="功能演示-1"><a href="#功能演示-1" class="headerlink" title="功能演示"></a>功能演示</h3><p>这里直接分享官方提供读取 Excel 的例子（<em>在实际项目中我对这部分做了简单的封装，涉及的地方比较多，就不分享出来了</em>）。</p>
<p><strong>实体对象</strong> （Excel 导入导出实体对象）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">@Data</span><br><span class="line">public class DemoData &#123;</span><br><span class="line">    private String string;</span><br><span class="line">    private Date date;</span><br><span class="line">    private Double doubleData;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>监听器</strong> （自定义 <code>AnalysisEventListener</code> 一次读取 5 条数据存储到数据库）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 有个很重要的点 DemoDataListener 不能被spring管理，要每次读取excel都要new,然后里面用到spring可以构造方法传进去</span><br><span class="line">public class DemoDataListener extends AnalysisEventListener&lt;DemoData&gt; &#123;</span><br><span class="line">    private static final Logger LOGGER &#x3D; LoggerFactory.getLogger(DemoDataListener.class);</span><br><span class="line">    &#x2F;**</span><br><span class="line">     * 每隔5条存储数据库，实际使用中可以3000条，然后清理list ，方便内存回收</span><br><span class="line">     *&#x2F;</span><br><span class="line">    private static final int BATCH_COUNT &#x3D; 5;</span><br><span class="line">    List&lt;DemoData&gt; list &#x3D; new ArrayList&lt;DemoData&gt;();</span><br><span class="line">    &#x2F;**</span><br><span class="line">     * 假设这个是一个DAO，当然有业务逻辑这个也可以是一个service。当然如果不用存储这个对象没用。</span><br><span class="line">     *&#x2F;</span><br><span class="line">    private DemoDAO demoDAO;</span><br><span class="line">    public DemoDataListener() &#123;</span><br><span class="line">        &#x2F;&#x2F; 这里是demo，所以随便new一个。实际使用如果到了spring,请使用下面的有参构造函数</span><br><span class="line">        demoDAO &#x3D; new DemoDAO();</span><br><span class="line">    &#125;</span><br><span class="line">    &#x2F;**</span><br><span class="line">     * 如果使用了spring,请使用这个构造方法。每次创建Listener的时候需要把spring管理的类传进来</span><br><span class="line">     *</span><br><span class="line">     * @param demoDAO</span><br><span class="line">     *&#x2F;</span><br><span class="line">    public DemoDataListener(DemoDAO demoDAO) &#123;</span><br><span class="line">        this.demoDAO &#x3D; demoDAO;</span><br><span class="line">    &#125;</span><br><span class="line">    &#x2F;**</span><br><span class="line">     * 这个每一条数据解析都会来调用</span><br><span class="line">     *</span><br><span class="line">     * @param data</span><br><span class="line">     *            one row value. Is is same as &#123;@link AnalysisContext#readRowHolder()&#125;</span><br><span class="line">     * @param context</span><br><span class="line">     *&#x2F;</span><br><span class="line">    @Override</span><br><span class="line">    public void invoke(DemoData data, AnalysisContext context) &#123;</span><br><span class="line">        LOGGER.info(&quot;解析到一条数据:&#123;&#125;&quot;, JSON.toJSONString(data));</span><br><span class="line">        list.add(data);</span><br><span class="line">        &#x2F;&#x2F; 达到BATCH_COUNT了，需要去存储一次数据库，防止数据几万条数据在内存，容易OOM</span><br><span class="line">        if (list.size() &gt;&#x3D; BATCH_COUNT) &#123;</span><br><span class="line">            saveData();</span><br><span class="line">            &#x2F;&#x2F; 存储完成清理 list</span><br><span class="line">            list.clear();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    &#x2F;**</span><br><span class="line">     * 所有数据解析完成了 都会来调用</span><br><span class="line">     *</span><br><span class="line">     * @param context</span><br><span class="line">     *&#x2F;</span><br><span class="line">    @Override</span><br><span class="line">    public void doAfterAllAnalysed(AnalysisContext context) &#123;</span><br><span class="line">        &#x2F;&#x2F; 这里也要保存数据，确保最后遗留的数据也存储到数据库</span><br><span class="line">        saveData();</span><br><span class="line">        LOGGER.info(&quot;所有数据解析完成！&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">    &#x2F;**</span><br><span class="line">     * 加上存储数据库</span><br><span class="line">     *&#x2F;</span><br><span class="line">    private void saveData() &#123;</span><br><span class="line">        LOGGER.info(&quot;&#123;&#125;条数据，开始存储数据库！&quot;, list.size());</span><br><span class="line">        demoDAO.save(list);</span><br><span class="line">        LOGGER.info(&quot;存储数据库成功！&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>持久层</strong> (mybatis 或者 jpa 来做都行)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;**</span><br><span class="line"> * 假设这个是你的DAO存储。当然还要这个类让spring管理，当然你不用需要存储，也不需要这个类。</span><br><span class="line"> **&#x2F;</span><br><span class="line">public class DemoDAO &#123;</span><br><span class="line">    public void save(List&lt;DemoData&gt; list) &#123;</span><br><span class="line">        &#x2F;&#x2F; 如果是mybatis,尽量别直接调用多次insert,自己写一个mapper里面新增一个方法batchInsert,所有数据一次性插入</span><br><span class="line">        System.out.println(list);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>读取数据</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">String fileName &#x3D; &quot;src&#x2F;test&#x2F;resources&#x2F;demo&#x2F;demo.xlsx&quot;;</span><br><span class="line">&#x2F;&#x2F; 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭</span><br><span class="line">EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();</span><br></pre></td></tr></table></figure>

<p><strong>输出结果</strong> （已过滤非必要数据）</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">2020-09-16 08:14:33.727 DEBUG [main] com.alibaba.excel.context.AnalysisContextImpl:91 - Began to read：ReadSheetHolder&#123;sheetNo&#x3D;0, sheetName&#x3D;&#39;Sheet1&#39;&#125; com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder@6f3b5d16</span><br><span class="line">2020-09-16 08:14:33.870 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1577811661000,&quot;doubleData&quot;:1.0,&quot;string&quot;:&quot;字符串0&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.870 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1577898061000,&quot;doubleData&quot;:2.0,&quot;string&quot;:&quot;字符串1&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.871 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1577984461000,&quot;doubleData&quot;:3.0,&quot;string&quot;:&quot;字符串2&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.871 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1578070861000,&quot;doubleData&quot;:4.0,&quot;string&quot;:&quot;字符串3&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.872 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1578157261000,&quot;doubleData&quot;:5.0,&quot;string&quot;:&quot;字符串4&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.872 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:80 - 5条数据，开始存储数据库！</span><br><span class="line">[DemoData(string&#x3D;字符串0, date&#x3D;Wed Jan 01 01:01:01 CST 2020, doubleData&#x3D;1.0), DemoData(string&#x3D;字符串1, date&#x3D;Thu Jan 02 01:01:01 CST 2020, doubleData&#x3D;2.0), DemoData(string&#x3D;字符串2, date&#x3D;Fri Jan 03 01:01:01 CST 2020, doubleData&#x3D;3.0), DemoData(string&#x3D;字符串3, date&#x3D;Sat Jan 04 01:01:01 CST 2020, doubleData&#x3D;4.0), DemoData(string&#x3D;字符串4, date&#x3D;Sun Jan 05 01:01:01 CST 2020, doubleData&#x3D;5.0)]</span><br><span class="line">2020-09-16 08:14:33.874 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:82 - 存储数据库成功！</span><br><span class="line">2020-09-16 08:14:33.875 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1578243661000,&quot;doubleData&quot;:6.0,&quot;string&quot;:&quot;字符串5&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.875 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1578330061000,&quot;doubleData&quot;:7.0,&quot;string&quot;:&quot;字符串6&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.876 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1578416461000,&quot;doubleData&quot;:8.0,&quot;string&quot;:&quot;字符串7&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.876 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1578502861000,&quot;doubleData&quot;:9.0,&quot;string&quot;:&quot;字符串8&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.876 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:54 - 解析到一条数据:&#123;&quot;date&quot;:1578589261000,&quot;doubleData&quot;:10.0,&quot;string&quot;:&quot;字符串9&quot;&#125;</span><br><span class="line">2020-09-16 08:14:33.877 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:80 - 5条数据，开始存储数据库！</span><br><span class="line">[DemoData(string&#x3D;字符串5, date&#x3D;Mon Jan 06 01:01:01 CST 2020, doubleData&#x3D;6.0), DemoData(string&#x3D;字符串6, date&#x3D;Tue Jan 07 01:01:01 CST 2020, doubleData&#x3D;7.0), DemoData(string&#x3D;字符串7, date&#x3D;Wed Jan 08 01:01:01 CST 2020, doubleData&#x3D;8.0), DemoData(string&#x3D;字符串8, date&#x3D;Thu Jan 09 01:01:01 CST 2020, doubleData&#x3D;9.0), DemoData(string&#x3D;字符串9, date&#x3D;Fri Jan 10 01:01:01 CST 2020, doubleData&#x3D;10.0)]</span><br><span class="line">2020-09-16 08:14:33.877 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:82 - 存储数据库成功！</span><br><span class="line">2020-09-16 08:14:33.877 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:80 - 0条数据，开始存储数据库！</span><br><span class="line">[]</span><br><span class="line">2020-09-16 08:14:33.877 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:82 - 存储数据库成功！</span><br><span class="line">2020-09-16 08:14:33.877 INFO [main] com.alibaba.easyexcel.test.demo.read.DemoDataListener:73 - 所有数据解析完成！</span><br><span class="line"></span><br><span class="line">Process finished with exit code 0</span><br></pre></td></tr></table></figure>

<h2 id="Hutool"><a href="#Hutool" class="headerlink" title="Hutool"></a>Hutool</h2><p><img src="http://iubest.gitee.io/pic/640-1601003797238.png" alt="img"></p>
<h3 id="介绍-2"><a href="#介绍-2" class="headerlink" title="介绍"></a>介绍</h3><p><strong>Hutool 是一个非常实用的 Java 工具类库，对文件、流、加密解密、转码、正则、线程、XML 等 JDK 方法进行了封装。</strong></p>
<p>非常使用的开源工具类库，推荐小伙伴们在自己项目中使用。</p>
<p>官方是这样介绍 Hutool 的：</p>
<p><img src="http://iubest.gitee.io/pic/640-1601003797106.png" alt="img"></p>
<h3 id="引入依赖-2"><a href="#引入依赖-2" class="headerlink" title="引入依赖"></a>引入依赖</h3><p>Maven</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- https:&#x2F;&#x2F;mvnrepository.com&#x2F;artifact&#x2F;cn.hutool&#x2F;hutool-all --&gt;</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;cn.hutool&lt;&#x2F;groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;hutool-all&lt;&#x2F;artifactId&gt;</span><br><span class="line">    &lt;version&gt;5.4.2&lt;&#x2F;version&gt;</span><br><span class="line">&lt;&#x2F;dependency&gt;</span><br></pre></td></tr></table></figure>

<p>Gradle</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; https:&#x2F;&#x2F;mvnrepository.com&#x2F;artifact&#x2F;cn.hutool&#x2F;hutool-all</span><br><span class="line">compile group: &#39;cn.hutool&#39;, name: &#39;hutool-all&#39;, version: &#39;5.4.2&#39;</span><br></pre></td></tr></table></figure>

<h3 id="功能演示-2"><a href="#功能演示-2" class="headerlink" title="功能演示"></a>功能演示</h3><p>简单演示几个比较实用的功能。</p>
<h4 id="邮件"><a href="#邮件" class="headerlink" title="邮件"></a>邮件</h4><p>在 Java 中发送邮件主要品依靠 <code>javax.mail</code> 包，但是由于使用比较繁琐，因此 Hutool 针对其做了封装。由于依赖第三方包，因此将此工具类归类到 extra 模块中。</p>
<p>实际项目中可以自定义邮箱配置，然后让配置保存在数据库，并在缓存中保存一份。</p>
<p>如果不想自定义配置的话，直接在配置文件中把邮箱配置写死就行了。</p>
<p>有了邮件的相关配置之后，定义邮件服务器之后即可发送邮件，非常方便：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">MailAccount account &#x3D; new MailAccount();</span><br><span class="line">account.setHost(&quot;smtp.yeah.net&quot;);</span><br><span class="line">account.setPort(&quot;25&quot;);</span><br><span class="line">account.setAuth(true);</span><br><span class="line">account.setFrom(&quot;hutool@yeah.net&quot;);</span><br><span class="line">account.setUser(&quot;hutool&quot;);</span><br><span class="line">account.setPass(&quot;q1w2e3&quot;);</span><br><span class="line"></span><br><span class="line">MailUtil.send(account, CollUtil.newArrayList(&quot;hutool@foxmail.com&quot;), &quot;测试&quot;, &quot;邮件来自Hutool测试&quot;, false);</span><br></pre></td></tr></table></figure>

<h4 id="唯一-ID"><a href="#唯一-ID" class="headerlink" title="唯一 ID"></a>唯一 ID</h4><p>在分布式环境中，唯一 ID 生成应用十分广泛，生成方法也多种多样，Hutool 针对一些常用生成策略做了简单封装。</p>
<p><img src="http://iubest.gitee.io/pic/640-1601167847698.png" alt="img"></p>
<p><a target="_blank" rel="noopener" href="https://juejin.im/post/6844903935296176141">https://juejin.im/post/6844903935296176141</a></p>
<p>Hutool 提供的唯一 ID 生成器的工具类，涵盖了：</p>
<ul>
<li><strong>UUID</strong></li>
<li><strong>ObjectId</strong>（MongoDB）</li>
<li><strong>Snowflake</strong>（Twitter）</li>
</ul>
<p>拿 UUID 举例！</p>
<p>Hutool 重写<code>java.util.UUID</code>的逻辑，对应类为<code>cn.hutool.core.lang.UUID</code>，使生成不带-的 UUID 字符串不再需要做字符替换，<strong>性能提升一倍左右</strong>。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;生成的UUID是带-的字符串，类似于：a5c8a5e8-df2b-4706-bea4-08d0939410e3</span><br><span class="line">String uuid &#x3D; IdUtil.randomUUID();</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;生成的是不带-的字符串，类似于：b17f24ff026d40949c85a24f4f375d42</span><br><span class="line">String simpleUUID &#x3D; IdUtil.simpleUUID();</span><br></pre></td></tr></table></figure>

<h4 id="Http-请求工具类"><a href="#Http-请求工具类" class="headerlink" title="Http 请求工具类"></a>Http 请求工具类</h4><p>针对最为常用的 GET 和 POST 请求，HttpUtil 封装了两个方法，</p>
<ul>
<li><code>HttpUtil.get</code></li>
<li><code>HttpUtil.post</code></li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 最简单的HTTP请求，可以自动通过header等信息判断编码，不区分HTTP和HTTPS</span><br><span class="line">String result1 &#x3D; HttpUtil.get(&quot;https:&#x2F;&#x2F;www.baidu.com&quot;);</span><br><span class="line">&#x2F;&#x2F; 当无法识别页面编码的时候，可以自定义请求页面的编码</span><br><span class="line">String result2 &#x3D; HttpUtil.get(&quot;https:&#x2F;&#x2F;www.baidu.com&quot;, CharsetUtil.CHARSET_UTF_8);</span><br><span class="line">&#x2F;&#x2F;可以单独传入http参数，这样参数会自动做URL编码，拼接在URL中</span><br><span class="line">HashMap&lt;String, Object&gt; paramMap &#x3D; new HashMap&lt;&gt;();</span><br><span class="line">paramMap.put(&quot;city&quot;, &quot;北京&quot;);</span><br><span class="line">String result3 &#x3D; HttpUtil.get(&quot;https:&#x2F;&#x2F;www.baidu.com&quot;, paramMap);</span><br></pre></td></tr></table></figure>

<h4 id="缓存"><a href="#缓存" class="headerlink" title="缓存"></a>缓存</h4><p>Hutool 提供了常见的几种缓存策略的实现：</p>
<ol>
<li><strong>FIFO(first in first out)</strong> ：先进先出策略。</li>
<li><strong>LFU(least frequently used)</strong> ：最少使用率策略。</li>
<li><strong>LFU(least frequently used)</strong> ：最少使用率策略。</li>
<li>定时缓存 ：对被缓存的对象定义一个过期时间，当对象超过过期时间会被清理。</li>
<li>……</li>
</ol>
<p>FIFO(first in first out) 策略缓存使用:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">Cache&lt;String,String&gt; fifoCache &#x3D; CacheUtil.newFIFOCache(3);</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;加入元素，每个元素可以设置其过期时长，DateUnit.SECOND.getMillis()代表每秒对应的毫秒数，在此为3秒</span><br><span class="line">fifoCache.put(&quot;key1&quot;, &quot;value1&quot;, DateUnit.SECOND.getMillis() * 3);</span><br><span class="line">fifoCache.put(&quot;key2&quot;, &quot;value2&quot;, DateUnit.SECOND.getMillis() * 3);</span><br><span class="line">fifoCache.put(&quot;key3&quot;, &quot;value3&quot;, DateUnit.SECOND.getMillis() * 3);</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;由于缓存容量只有3，当加入第四个元素的时候，根据FIFO规则，最先放入的对象将被移除</span><br><span class="line">fifoCache.put(&quot;key4&quot;, &quot;value4&quot;, DateUnit.SECOND.getMillis() * 3);</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;value1为null</span><br><span class="line">String value1 &#x3D; fifoCache.get(&quot;key1&quot;);</span><br></pre></td></tr></table></figure>

<h4 id="控制台打印封装-Console"><a href="#控制台打印封装-Console" class="headerlink" title="控制台打印封装-Console"></a>控制台打印封装-Console</h4><p>一般情况下，我们打印信息到控制台小伙伴们应该再熟悉不过了！</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">System.out.println(&quot;Hello World&quot;);</span><br></pre></td></tr></table></figure>

<p>但是，这种方式不满足很多场景的需要：</p>
<ol>
<li>不支持参数，对象打印需要拼接字符串</li>
<li>不能直接打印数组，需要手动调用<code>Arrays.toString</code></li>
</ol>
<p>为此，Hutool 封装了<code>Console</code>对象。</p>
<blockquote>
<p>Console 对象的使用更加类似于 Javascript 的<code>console.log()</code>方法，这也是借鉴了 JS 的一个语法糖。</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">String[] a &#x3D; &#123;&quot;java&quot;, &quot;c++&quot;, &quot;c&quot;&#125;;</span><br><span class="line">Console.log(a);&#x2F;&#x2F;控制台输出：[java, c++, c]</span><br><span class="line"></span><br><span class="line">Console.log(&quot;This is Console log for &#123;&#125;.&quot;, &quot;test&quot;);&#x2F;&#x2F;控制台输出：This is Console log for test.</span><br></pre></td></tr></table></figure>

<h3 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h3><p>[1]oshi: <em><a target="_blank" rel="noopener" href="https://github.com/oshi/oshi">https://github.com/oshi/oshi</a></em>[2]EasyExcel: <em><a target="_blank" rel="noopener" href="https://github.com/alibaba/easyexcel">https://github.com/alibaba/easyexcel</a></em>[3]Hutool: <em><a target="_blank" rel="noopener" href="https://github.com/looly/hutool">https://github.com/looly/hutool</a></em>[4]JNA(Java Native Access): <em><a target="_blank" rel="noopener" href="https://github.com/java-native-access/jna">https://github.com/java-native-access/jna</a></em></p>
<h2 id="闲聊"><a href="#闲聊" class="headerlink" title="闲聊"></a>闲聊</h2><p>其实今天本来是准备更新一篇系统设计面试指南的，毕竟系统设计几乎也是面试必问了，非常重要。 最近询问这方面问题的小伙伴比较多。</p>
<p>文章大概要写啥内容都构思好了，结果还是过于天真。因为涉及到的内容和知识点太多了。预计会在下周分享（如果中途没出啥状况的话）。</p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2020/11/11/develop/%E6%8F%90%E9%AB%98%E7%94%9F%E4%BA%A7%E6%95%88%E7%8E%87%EF%BC%813%E4%B8%AA%E5%B8%B8%E7%94%A8%E7%9A%84%E5%BC%80%E6%BA%90%E5%B7%A5%E5%85%B7%E5%BA%93%E5%88%86%E4%BA%AB/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/develop/" rel="tag">develop</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/11/11/develop/%E5%88%AB%E7%94%A8Date%E4%BA%86%EF%BC%8CJava8%E6%96%B0%E7%89%B9%E6%80%A7%E4%B9%8B%E6%97%A5%E6%9C%9F%E5%A4%84%E7%90%86%EF%BC%8C%E7%8E%B0%E5%9C%A8%E5%AD%A6%E4%BC%9A%E4%B9%9F%E4%B8%8D%E8%BF%9F/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            别用Date了，Java8新特性之日期处理，现在学会也不迟.md
          
        </div>
      </a>
    
    
      <a href="/2020/11/11/develop/%E6%90%9E%E5%AE%9Apython%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%92%8C%E5%A4%9A%E8%BF%9B%E7%A8%8B/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">搞定python多线程和多进程.md</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2020
        <i class="ri-heart-fill heart_icon"></i> TzWind
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Hexo"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="http://www.baidu.com">百度</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>